package com.study;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.study.service.ClassesService;
import com.study.service.StudentService;
import com.study.service.TableManagerService;

public class TestApp {
	private StudentService studentService;
	private ClassesService classesService;
	
	private TableManagerService tableMgrService;
	
	@Before
	public void init(){
		try{
			ApplicationContext ctx=new ClassPathXmlApplicationContext("applicationContext.xml");
			studentService = ctx.getBean(StudentService.class);
			classesService = ctx.getBean(ClassesService.class);
			tableMgrService = ctx.getBean(TableManagerService.class);
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	
	@Test
	public void testF(){
		try{
			//query、select、find开头的都执行丛库，其它未主库
			studentService.delete(10);//主库
			System.out.println("1111"+studentService.queryById(2));//查询丛库
			System.out.println("2222"+studentService.xQueryById(2));//查询主库
			System.out.println("3333"+studentService.yQueryById(2));//查询主库
			System.out.println("4444"+studentService.selectById(2));//查询丛库
			System.out.println("5555"+studentService.zQueryById(2));//查询主库
			classesService.delete(2);
			
			
			
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	
	@Test
	public void testTableMgr(){
		try{
			tableMgrService.createTable("tab_60005");
			System.out.println("表是否存在："+tableMgrService.existTable("tab_60001"));
			
			System.out.println("删除表");
			tableMgrService.dropTable("tab_60005");
			System.out.println("删除表结束");
			
			
			
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	
	@After
	public void destroy(){
		System.out.println("the end");
	}
}
